package edu.online.dal;

import edu.online.entity.LessonEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface LessonEntityMapper {
    @Delete({
        "delete from lesson",
        "where LessonID = #{lessonid,jdbcType=CHAR}"
    })
    int deleteByPrimaryKey(String lessonid);

    @Insert({
        "insert into lesson (LessonID, CourseID, ",
        "TeacherId, firstDay, PersonNum, ",
        "LeaveNum, SwitchNum)",
        "values (#{lessonid,jdbcType=CHAR}, #{courseid,jdbcType=CHAR}, ",
        "#{teacherid,jdbcType=CHAR}, #{firstday,jdbcType=DATE}, #{personnum,jdbcType=SMALLINT}, ",
        "#{leavenum,jdbcType=SMALLINT}, #{switchnum,jdbcType=SMALLINT})"
    })
    int insert(LessonEntity record);

    @InsertProvider(type=LessonEntitySqlProvider.class, method="insertSelective")
    int insertSelective(LessonEntity record);

    @Select({
        "select",
        "LessonID, CourseID, TeacherId, firstDay, PersonNum, LeaveNum, SwitchNum",
        "from lesson",
        "where LessonID = #{lessonid,jdbcType=CHAR}"
    })
    @Results({
        @Result(column="LessonID", property="lessonid", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="CourseID", property="courseid", jdbcType=JdbcType.CHAR),
        @Result(column="TeacherId", property="teacherid", jdbcType=JdbcType.CHAR),
        @Result(column="firstDay", property="firstday", jdbcType=JdbcType.DATE),
        @Result(column="PersonNum", property="personnum", jdbcType=JdbcType.SMALLINT),
        @Result(column="LeaveNum", property="leavenum", jdbcType=JdbcType.SMALLINT),
        @Result(column="SwitchNum", property="switchnum", jdbcType=JdbcType.SMALLINT)
    })
    LessonEntity selectByPrimaryKey(String lessonid);

    @UpdateProvider(type=LessonEntitySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(LessonEntity record);

    @Update({
        "update lesson",
        "set CourseID = #{courseid,jdbcType=CHAR},",
          "TeacherId = #{teacherid,jdbcType=CHAR},",
          "firstDay = #{firstday,jdbcType=DATE},",
          "PersonNum = #{personnum,jdbcType=SMALLINT},",
          "LeaveNum = #{leavenum,jdbcType=SMALLINT},",
          "SwitchNum = #{switchnum,jdbcType=SMALLINT}",
        "where LessonID = #{lessonid,jdbcType=CHAR}"
    })
    int updateByPrimaryKey(LessonEntity record);
}